package com.zhangye.test.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhangye.test.model.Version;
import com.zhangye.test.service.VersionService;

@Controller
@RequestMapping("api/version")
public class VersionApi {
	
	@Autowired
	private VersionService versionService;

	
	@ResponseBody
	@RequestMapping("/judge")
	public ApiResult judge(){
		ApiResult result = new ApiResult();
		result.msg.desc = "";
		result.msg.status = 1;
		return result;
	}

	/**
	 * 获取当前版本号
	 * 作者：张叶
	 * 创建时间：2016年8月12日 上午9:33:11
	 */
    @ResponseBody
    @RequestMapping(value = "/getVersion", method = RequestMethod.GET)
    public ApiResult login() {
        ApiResult result = new ApiResult();
        	String where = " order by id desc limit 0,1";
        	List<Version> list = versionService.selectByWhere(where);
        	if(list.size() > 0){
        		result.msg.desc = "获取成功";
        		result.msg.status = 0;
        		result.data.put("appsize", list.get(0).getAppsize());
        		result.data.put("description", list.get(0).getDescription());
        		result.data.put("id", list.get(0).getId());
        		result.data.put("remark", list.get(0).getRemark());
        		result.data.put("updatetime", list.get(0).getUpdatetime());
        		result.data.put("updateurl", list.get(0).getUpdateurl());
        		result.data.put("versioncode", list.get(0).getVersioncode());
        		result.data.put("versionname", list.get(0).getVersionname());
        	}else{
        		result.msg.status = 1;
    			result.msg.desc = "暂无最新版本";
    		}
        return result;
    }

}
